// const { json } = require("express");

new Vue({
	el: '#app',
	data: function () {
		return {
			popupRemoveConfim:false,//删除确认框
			showErrorMsg:false,
			errormsg:'',
			addTimeIndex:'',


			searchDate:'',
			timevalue:'',

			addDay:'', //哪一天的日期下面进行添加排班
			loading:true,
			host: window.location.protocol+'//'+window.location.host,
			communityId:'',
			userId:'',
			msg:'',
			errorPopup:false,
			errorPopups:false,
			additionalAmount:0,
			merchantName:'',
			merchantNo:'',
			userName:'',
			userAddress:'',
			remark:'',
			isShow:false,
			nodatashow:false,
			auditShow:false,
			feeId:'',
			feeName:'',
			wxAppId:'',
			openId:'',
			mobile:'',
			identityType:'',
			submitBstap:true,
			requestHeaders:'',

		}
	},
	created() {
		this.communityId=this.getUrlParam("communityId");
		this.wxAppId=this.getUrlParam("wxAppId");
		this.openId=this.getUrlParam("openId");
		this.openid_t=this.getUrlParam("openId");
		this.mobile=this.getUrlParam("mobile");
		this.identityType=this.getUrlParam("identityType");
		this.wxAppId_t=this.getUrlParam("wxAppId");
		this.requestHeaders=getRequestHeaders('01',this.communityId);//获取请求头
        // console.log(this.requestHeaders)
		console.log(this.localStorageCommunityId);
		console.log("wxAppId",this.wxAppId_t);
		// this.searchDate=this.getUrlParam("searchDate")?this.getUrlParam("searchDate"):'';
		// this.selectTypeId=this.getUrlParam("selectTypeId")?this.getUrlParam("selectTypeId"):'';
		// this.selectTypeValue=this.getUrlParam("selectTypeValue")?this.getUrlParam("selectTypeValue"):'';
		this.listPayFee();
		this.queryUserStatus();
	},
	methods: {
		// 查询维修类型
		listPayFee(){
			var that=this;
			var url=this.host+'/app/fee.listPayFee';
			console.log('communityId:'+this.communityId)
			var params={
				communityId:this.communityId,
				row:50,
				page:1
			}
			$.ajax({
				url : url,
				type: 'GET',
				dataType:'json',
				headers:that.requestHeaders,
				data: params,
				success : function (res){
					console.log('res',res);
					if(res.code=='0'){
						that.isShow = true;
						if(res.data){
							that.additionalAmount = res.data.additionalAmount;
							that.merchantName = res.data.merchantName;
							that.merchantNo = res.data.merchantNo;
							that.userName = res.data.userName;
							that.userAddress = res.data.userAddress;
							that.remark = res.data.remark;
							that.feeId = res.data.feeId;
							that.feeName = res.data.feeName;
						}
					}else{
						that.nodatashow = true
					}
				},
				error:function(res){
					that.errorPopup=true;
					that.msg=res.responseText?res.responseText:'请求超时'
					console.log(res.responseText)

				}
			})
		},
		timeBlur(){
			var that=this;
			if(this.timevalue>0 && this.timevalue<1440){
				this.timevalue=this.getInteger(this.timevalue)
			}else{
				this.showErrorMsg=true;
				this.errormsg='时间间隔为整数且不可超过1440(分钟)';
				setTimeout(function(){
					that.showErrorMsg=false;
				},1500)
				this.timevalue='';
				return;
			}

		},
		//获取小数点前面的数字
		getInteger(num){
			var val=num.toString();
			if(val.indexOf('.')==-1){
				return val;
			}else{
				return val.substring(0,val.indexOf('.'))
			}
		},
		//时分比较
		timeComparison(start,end){
			//分割开始时间的时
			let kaiShi = start.split(":")[0];
			//分割开始时间的分
			let kaiFen = start.split(":")[1];
			//分割结束时间的时
			let jieShi = end.split(":")[0];
			//分割结束时间的分
			let jieFen = end.split(":")[1];
			//判断两者的时
			if(kaiShi < jieShi){
				return false;
			}else if(kaiShi == jieShi){
				//如果等于的话就判断两者的分
				if(kaiFen < jieFen){
					return false;
				}else{
					return true;
				}
			}else{
				return true;
			}
		},
		getUrlParam(name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
			var r = window.location.search.substr(1).match(reg); //匹配目标参数
			if (r != null) return unescape(r[2]);
			return null; //返回参数值

		},

		//添加值班人员先判断维修类型是否已选
		addPeople(){
			var that=this;
			this.showErrorMsg=true;
			this.errormsg='请先选择维修类型';
			setTimeout(function(){
				that.showErrorMsg=false;
			},1500)
			return;
		},
		payHistory(){
			var url=this.host+'/userPayHistory.html?communityId='+this.communityId+'&userId='+this.userId;
			window.location.href = url;
		},
		payMoney(){
			var that=this;
			var url=this.host+'/app/fee.xcxPayFee';
			var tourl = this.host+'/userPayHistory.html?communityId='+this.communityId+'&userId='+this.userId;
			var params={
				feeId:that.feeId,
				appid:that.wxAppId_t,
				openid:that.openid_t,
				mobile:that.mobile,
			}
			if(that.submitBstap==false){
				return;
			}
			that.submitBstap=false
			$.ajax({
				url : url,
				type: 'POST',
				contentType: 'text/plain',
				headers:that.requestHeaders,
				data: JSON.stringify(params),
				success : function (res){
					var data = JSON.parse(res);
					// that.submitBstap=true
					if(data.code=='0000'){
						var vdata = JSON.parse(data.data);
						//如果是小程序
						let payData = {
							timeStamp: vdata.subTimeStamp,
							nonceStr:vdata.subNonceStr,
							package: encodeURIComponent(vdata.subPackage),
							signType: vdata.subSignType,
							paySign: vdata.subPaySign,
							successRedirectUrl:encodeURIComponent(tourl),
							failRedirectUrl:encodeURIComponent(tourl)
						}
						let payDataStr = JSON.stringify(payData);//因为要把参数传递给小程序，所以这里需要转为字符串
						const url = '/pages/activites/weipay?payDataStr=' + payDataStr;
						wx.miniProgram.navigateTo({url: url});
					}else{
						that.errorPopup=true;
						that.msg=data.msg
					}
				},
				error:function(res){
					that.submitBstap=true
					that.errorPopup=true;
					that.msg=res.responseText?res.responseText:'请求超时'
					console.log(res.responseText)

				}
			})
		},
		queryUserStatus(){
			var that=this;
			var url=this.host+'/app/owner.queryUserStatus';
			console.log('communityId:'+this.communityId)
			var params={
				communityId:this.communityId,
				wxAppId:that.wxAppId,
				mobile:that.mobile
			}
			$.ajax({
				url : url,
				type: 'POST',
				contentType: 'text/plain',
				headers:that.requestHeaders,
				data: JSON.stringify(params),
				success : function (res){
					var data = JSON.parse(res)
					console.log(data)
					if(data.code=='200'){
						// if(that.identityType=='1005'){
							if(data.auditStatus=='9999' || data.auditStatus=='1200'){
								that.errorPopups=true;
								that.msg='您还未认证，请您先完成房屋认证？'
							}else if(data.auditStatus=='1000'){
								that.auditShow = true;
							}

						// }
					}else{
						that.errorPopup=true;
						that.msg=data.msg
					}
				},
				error:function(res){
					that.errorPopup=true;
					that.msg=res.responseText?res.responseText:'请求超时'
					console.log(res.responseText)

				}
			})
		},
		identification(){
			var url=this.host+'/identityAuthentication.html?openId='+this.openId+'&wxAppId='+this.wxAppId_t+'&communityId='+this.communityId+'&mobile='+this.mobile;
			window.location.href = url;
		}
	}
});